<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>员工列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/js/layui/css/layui.css" media="all">
    <style type="text/css">
        .layui-table-cell{height:40px;line-height:40px;}
    </style>
</head>
<body >
<!--搜索框-->
<!--<div class="layui-form">-->
<!--    <div class="layui-form-item" style="margin-bottom: 30px;text-align: center;">-->
<!--        <div class="layui-inline">-->
<!--            &lt;!&ndash;<label class="layui-form-label">员工姓名或编号</label>&ndash;&gt;-->
<!--            <div class="layui-input-inline">-->
<!--                <input type="text" name="name" placeholder="请输入姓名" autocomplete="off" class="layui-input" />-->
<!--            </div>-->
<!--        </div>-->
<!--        <div class="layui-inline">-->
<!--            <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="search-qiye-submit">-->
<!--                <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>-->
<!--            </button>-->
<!--        </div>-->
<!--    </div>-->
<!--</div>-->

<blockquote class="layui-elem-quote quoteBox mod_default_box">
    <form class="layui-form">
        <div class="layui-inline">
            <label class="layui-form-label">关键字</label>
            <div class="layui-input-inline">
                <input type="text" id="name" name="name" placeholder="编号、姓名、联系方式" autocomplete="off" class="layui-input" />
            </div>
            <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="search-qiye-submit">
                <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
            </button>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label">物业</label>
            <div class="layui-input-inline">
                <select name="city" lay-verify="" lay-filter="wuye" id="wuye" lay-search>
                    <option value="">选择物业</option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">企业</label>
            <div class="layui-input-inline">
                <select name="city" lay-verify="" lay-filter="qiye" id="qiye" lay-search>
                    <option value="">选择企业</option>
                </select>
            </div>
        </div>
    </form>
</blockquote>

<table class="layui-hide" id="test" lay-filter="qiye-table"></table>

<script type="text/html" id="qiye-toolbar">
    <a class="layui-btn  layui-btn-xs" lay-event="huifu">恢复员工</a>

    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete"><i class="layui-icon layui-icon-subtraction"></i>彻底删除</a>
    <!--<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>-->
</script>

<script src="/js/layui/layui.js"></script>

<script>
    layui.use(['table','upload'], function() {
        var $ = layui.$;
        var table = layui.table;
        var layer = layui.layer;
        var form = layui.form;
        var upload = layui.upload;

        var qiye = ""
        var wuye = ""
        var name = ""

        table.render({
            elem: '#test'
            , id: 'staff-table-id'//重载需要
            , url: '/staffHis/selectStaffHis'
            , title: '员工表'
            , cols: [[
                {type: 'numbers',title: '序号'}
                , {field: 'bh',align : 'center',width : 125, title: '员工编号'}
                , {field: 'name', width: 110, align: 'center', title: '姓名'}
                , {field: 'nicheng', width: 110, align: 'center', title: '昵称'}
                , {field: 'picture',align : 'center',title: '头像',width : 125,templet: '<div><img src="/upload/{{ d.picture }}" style="" onclick="previewImgs(this)"></div>'}
                ,{field:'sex',width : 60,align : 'center', title: '性别',templet: function (d) {
                        if (d.sex==0) return "女";
                        else if (d.sex==1) return "男";
                    }
                }
                , {field: 'phone',align : 'center',width : 125,title: '联系方式'}
                , {field: 'address',align : 'center',width : 125,title: '家庭住址'}
                , {field: 'guoji',align : 'center',width : 120, title: '国籍',templet: function (d) {
                        if (d.guoji=="null" || d.guoji==null || d.guoji=="undefined") return "";
                        else return d.guoji;
                    }}
                /*, {field: 'sfz',align : 'center',width : 180, title: '证件号'}*/
                , {field: 'cstime',align : 'center',width : 125, title: '出生日期'}
                , {field: 'wyName',align : 'center',width : 125, title: '所属物业' , templet:function(res){
                        if(res.wyName != undefined) {
                            return res.wyName
                        }else{
                            return ""
                        }
                    }}
                , {field: 'qyName',align : 'center',width : 125, title: '所属企业' , templet:function(res){
                        if(res.qyName != undefined) {
                            return res.qyName
                        }else{
                            return ""
                        }
                    }}
                , {field: 'cardNo',align : 'center',width : 120, title: '员工卡号'}
                , {field: 'createtime',align : 'center',width : 160, title: '删除时间'}
                , {field: 'operType',align : 'center',width : 120, title: '操作类型',templet: function (d) {
                        if (d.operType==0) return "批量删除";
                        else if (d.operType==1) return "单个删除";
                        else if (d.operType==2) return "企业删除";
                        else return "";
                    }
                }
                , {field: 'remark',align : 'center', width : 180,title: '删除原因'}
                , {toolbar: "#qiye-toolbar",align : 'center', width: 260, title: "操作",fixed: 'right'}
            ]]
            , page: true
            ,page: {
                curr: layui.data("staffHis_page").index
            },
            done: (res, curr, count) => {
                layui.data("staffHis_page", {
                    key: 'index',
                    value: curr
                });
            }
        });

        $.ajax({
            url:"/qiye/getAllQiye" ,
            success:function(res){
                if(res.code == 200) {
                    for(var i in res.data) {
                        $("#qiye").append("<option value='"+res.data[i].id+"'>"+res.data[i].qyname+"</option>")
                    }
                    form.render()
                }
            }
        })

        $.ajax({
            url:"/wuye/selectwuyestatus" ,
            success:function(res){
                if(res.code == 0) {
                    for(var i in res.data) {
                        $("#wuye").append("<option value='"+res.data[i].id+"'>"+res.data[i].wyname+"</option>")
                    }
                    form.render()
                }
            }
        })

        //搜索操作
        form.on('submit(search-qiye-submit)', function (data) {
            name = data.field.name
            table.reload('staff-table-id', {
                where: {"name": data.field.name , "qiye": qiye , "wuye":wuye}
                , page: {
                    curr: 1
                }
            });
            return false;
        });

        form.on('select(qiye)', function(data){
            qiye = data.value;
            name = $("#name").val();
            table.reload('staff-table-id', {
                where: {"qiye": qiye , "wuye":wuye , "name":name}
                , page: {
                    curr: 1
                }
            });
        });

        form.on('select(wuye)', function(data){
            wuye = data.value
            qiye = null
            name = $("#name").val();
            $.ajax({
                url:"/qiye/getAllQiye" ,
                data:{wuye:wuye} ,
                success:function(res){
                    if(res.code == 200) {
                        $("#qiye option:gt(0)").remove()
                        for(var i in res.data) {
                            $("#qiye").append("<option value='"+res.data[i].id+"'>"+res.data[i].qyname+"</option>")
                        }
                        form.render()
                    }
                }
            })
            table.reload('staff-table-id', {
                where: {"qiye": qiye , "wuye":wuye, "name":name}
                , page: {
                    curr: 1
                }
            });
        });


        //表操作  监听操作
        table.on('toolbar(qiye-table)', function (obj) {
            var data=obj.data;
            var event = obj.event;
            if (event === 'batchAdd') {
                $("#batchAdd").click();
            }
        })

        //表操作  监听操作
        table.on('tool(qiye-table)', function (obj) {
            var data=obj.data;
            var event = obj.event;
            //删除
            if (event === 'huifu') {
                layer.confirm('确定恢复员工数据？', function (index) {
                    $.ajax({
                        url: "/staffHis/hfStaff?id=" + data.id
                        , type: "GET"
                        , dataType: "json"
                        , success: function (data) {
                            if (data.code == 200) {
                                layer.msg("恢复成功");
                                table.reload("staff-table-id");
                            } else if (data.code == 500) {
                                layer.msg("恢复失败");
                            }else {
                                layer.msg("拒绝访问");
                            }
                        }
                        , error: function () {
                            console.log("ajax error");
                        }
                    });
                    layer.close(index);
                });
            } else if(event === 'delete'){
                layer.confirm("确定彻底删除吗？",function (index) {
                    $.ajax({
                        url: "/staffHis/deleteStaffHis?id=" + data.id
                        , type: "GET"
                        , success: function (data) {
                            if (data.code == 200) {
                                layer.msg("删除成功");
                                layer.close(index);
                                table.reload("staff-table-id");
                            } else if (data.code == 500) {
                                layer.msg("删除失败");
                            }else {
                                layer.msg("拒绝访问");
                            }
                        }
                        , error: function () {
                            console.log("ajax error");
                        }
                    });
                })
            }
        });
    });
</script>

<script>
    function previewImgs(obj) {
        var img = new Image();
        img.src = obj.src;
        //var height = img.height + 50; // 原图片大小
        //var width = img.width; //原图片大小
        var imgHtml = "<img src='" + obj.src + "' width='800px' height='500px'/>";
        //弹出层
        layer.open({
            type: 1,
            shade: 0.8,
            offset: 'auto',
            area: [800 + 'px', 550 + 'px'],// area: [width + 'px',height+'px'],  //原图显示
            shadeClose: true,
            scrollbar: false,
            title: "图片预览", //不显示标题
            content: imgHtml, //捕获的元素，注意：最好该指定的元素要存放在body最外层，否则可能被其它的相对元素所影响
            cancel: function () {
                //layer.msg('捕获就是从页面已经存在的元素上，包裹layer的结构', { time: 5000, icon: 6 });
            }
        });
    }
</script>
</body>
</html>